package de.dhbw.tinf11b.vfb;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;

import de.dhbw.tinf11b.vfb.exceptions.UnitNotFoundException;

public class Curriculum {
	protected String programName; // entspricht Studiengangsname
	protected DegreeType degreeType;
	protected List<Module> modules = new LinkedList<Module>(); // Liste von Modulen, die 210 Credits ergeben müssen
	
	/**
	 * 
	 * @param programName
	 * @param Bachelor of Science or Engineering
	 */
	public Curriculum(String programName, DegreeType degreeType) {
		this.programName = programName;
		this.degreeType = degreeType;
	}
	
	/**
	 * Add module to curriculum
	 * @param module to be appended to this curriculum
	 * @return <tt>true</tt> (as specified by {@link Collection#add})
	 */
	public boolean addModule(Module module) {
		return this.modules.add(module);
	}
	
	public int getSumCredits() {
		int sumCredits = 0;
		for(Module m : getModules()) {
			sumCredits = sumCredits + m.getCredits();
		}
		return sumCredits;
	}

	public String getProgramName() {
		return programName;
	}

	public void setProgramName(String programName) {
		this.programName = programName;
	}

	public DegreeType getDegreeType() {
		return degreeType;
	}

	public void setDegreeType(DegreeType degreeType) {
		this.degreeType = degreeType;
	}

	public List<Module> getModules() {
		return modules;
	}

	public void setModules(List<Module> modules) {
		this.modules = modules;
	}
	
	public Unit getUnitByName(String name) throws UnitNotFoundException {
		for(Module module : this.modules) {
			for(Entry<Unit, Float> unitEntry : module.getUnits().entrySet()) {
				if(unitEntry.getKey().getName().equals(name)) {
					return unitEntry.getKey();
				}
			}
		}
		
		throw new UnitNotFoundException();
	}
}
